﻿@model TestOnlineProject.Models.Entities.User
@{
    ViewBag.Title = "Edit";
}
<script type="text/javascript">
    $(document).ready(function() {
        $('.fileinput').fileinput();

        $('#FileUpload').bind('change', function() {
            var filename = $('#FileUpload').val();
            if (filename != "") {
                var extension = filename.replace(/^.*\./, '');
                if (extension == filename) {
                    extension = '';
                } else {
                    extension = extension.toLowerCase();
                }

                switch (extension) {
                case 'jpg':
                    break;
                case 'png':
                    break;
                case 'jpeg':
                    break;
                case 'gif':
                    break;
                default:
                    alert('Please select image file type jpg, png, jpeg or gif');
                    $('.fileinput').fileinput('reset');
                }
            }
        });
    });

    function validate() {
        var password = document.getElementById('Password');
        var reEnterPassword = document.getElementById('ReEnterPassword');
        if (password.value != reEnterPassword.value) {
            document.getElementById('ReEnterPassword_Message').innerHTML = "Re-Enter Password must equal Password.";
            return false;
        }
        return true;
    }
</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home", new { Area = "" }, new { }) / @Html.ActionLink("Users", "Index")
    / Edit User
</div>
<br />
<div class="main_nav">
    <span>
        <a href="@Url.Content("~/User/Details")?id=@Model.UserId">
            <img src="@Url.Content("~/Images/back button.png")"/>
        </a>
    </span>
</div>
<br />
<span class="require_info">(*) is required.</span>
@using (Html.BeginForm("Edit", "User", FormMethod.Post, new { enctype = "multipart/form-data", onsubmit = "return validate()" }))
{
    if (Model.RoleId == 1)
    {
    @Html.HiddenFor(model => model.RoleId)
    }

    @Html.HiddenFor(model => model.LastChangedTime)
    @Html.HiddenFor(model => model.UserId)
    @Html.HiddenFor(model => model.Username)
    <span class="errorMsg">@Html.ValidationSummary(true)</span>
    <table class="table table-bordered">
        <tr>
            <td style="width: 150px; text-align: right">
                <span>Username</span>
            </td>
            <td>
                @Html.DisplayFor(model => model.Username)
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                <span>E-Mail</span>
            </td>
            <td>
                <span class="errorMsg">@Html.ValidationMessageFor(model => model.Email)</span>
                @Html.TextBoxFor(model => model.Email)<span>&nbsp;(*)</span>
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
                <span>Full Name</span>
            </td>
            <td>
                <span class="errorMsg">@Html.ValidationMessageFor(model => model.FullName)</span>
                @Html.TextBoxFor(model => model.FullName)<span>&nbsp;(*)</span>
            </td>
        </tr>
        <tr>
            <td style="width: 150px; text-align: right">
                <span>Profile Picture</span>
            </td>
            <td>
                <div class="fileinput fileinput-new" data-provides="fileinput">
                    <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                        @if (@Model.ImageUrl == null)
                        {
                            <img data-src="holder.js/100%x100%" alt="..." src="~/Images/default_large.png" />
                        }
                        else
                        {
                            <img data-src="holder.js/100%x100%" alt="..." src="~/Images/Profile/@Model.ImageUrl" />
                        }
                    </div>
                    <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px;
                        max-height: 150px;">
                    </div>
                    <div id="selectPicture">
                        <span class="btn btn-default btn-file"><span class="fileinput-new">Select Picture</span>
                            <span class="fileinput-exists">Change picture</span>
                            <input type="file" name="FileUpload" id="FileUpload" title="Change picture">
                        </span><a style="margin:5px" href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">
                            Remove</a>
                    </div>
                </div>
            </td>
        </tr>
        @{
                        if (Model.RoleId != 1)
                        {
            <tr>
                <td style="text-align: right">
                    <span>Role</span>
                </td>
                <td>
                    <span class="errorMsg">@Html.ValidationMessageFor(model => model.RoleId)</span>
                    @Html.DropDownList("RoleId", String.Empty)<span>&nbsp;(*)</span>
                </td>
            </tr>
                        }
        }
        <tr>
            <td style="width: 100px; text-align: right">
                <span>Password</span>
            </td>
            <td>
                <span class="errorMsg">@Html.ValidationMessageFor(model => model.Password)</span>
                @Html.PasswordFor(model => model.Password, new { value = @Model.Password })<span>&nbsp;(*)</span>
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right">
                <span>Re-Enter Password</span>
            </td>
            <td>
                <span class="errorMsg" id="ReEnterPassword_Message"></span>
                <input type="password" id="ReEnterPassword" value="@Model.Password"/><span>&nbsp;(*)</span>
            </td>
        </tr>
        <tr>
            <td style="text-align: right">
            </td>
            <td>
                <button type="submit" value="Save" class="btn" style="width: 80px">
                    Save</button>
                @Html.ActionLink("Reset", "Edit", new { id = @Model.UserId }, new { @class = "btn", style = "width:54px" })
                @Html.ActionLink("Cancel", "Details", new { id = @Model.UserId }, new { @class = "btn", style = "width:54px" })
            </td>
        </tr>
    </table>
}